package com.centerserver;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;

import javax.swing.DefaultListModel;
import javax.swing.table.DefaultTableModel;

class ListenMonitorCommandThread extends Thread {

	private ServerSocket mServerSocket;
	private DefaultTableModel mMsgTableModel;

	public ListenMonitorCommandThread(DefaultTableModel tableModel) {
		mMsgTableModel = tableModel;
		try {
			mServerSocket = new ServerSocket(
					CenterServerConfig.PORT_MONITOR_END_SEND_COMMAND_TO);
		} catch (IOException e) {
			System.out.println("IOException in ListenMonitorCommand");
			e.printStackTrace();
		}
	}

	@Override
	public void run() {

		try {
			while (true) {

				Socket client = mServerSocket.accept();
				
				ProcessMonitorCommandThread processMonitorCommandThread = new ProcessMonitorCommandThread(
						mMsgTableModel, 
						client);
				processMonitorCommandThread.start();

			}
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
